<template>
	<view class="bank-page">
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index">
				<view class="name">{{ item.bank_name }}</view>
				<view class="look-box" @click="numShow = !numShow">
					<text class="mr-4">储蓄卡</text>
					<u-icon name="eye-off" color="#fff" size="28rpx"></u-icon>
				</view>
				<view class="number-box">
					<view class="number" v-if="numShow">{{ item.card_no }}</view>
					<view class="hide" v-else>
						<view class="dot-box">
							<view class="dot"></view>
							<view class="dot"></view>
							<view class="dot"></view>
							<view class="dot"></view>
						</view>
						<view class="dot-box">
							<view class="dot"></view>
							<view class="dot"></view>
							<view class="dot"></view>
							<view class="dot"></view>
						</view>
						<view class="dot-box">
							<view class="dot"></view>
							<view class="dot"></view>
							<view class="dot"></view>
							<view class="dot"></view>
						</view>
					</view>
				</view>
				<view class="mord" @click="showActionSheet(item, index)">
					<u-icon name="more-dot-fill" color="rgba(255, 255, 255, 0.8)" size="34rpx"></u-icon>
				</view>
			</view>
		</view>
		<view class="add" @click="addBank">
			<u-icon name="plus" color="#333" size="36rpx" bold></u-icon>
			<view class="label">添加银行卡</view>
		</view>
	</view>
</template>

<script>
	import { getBankCardInfo, delBankCard } from '@/api/api'
	
	export default {
		data () {
			return {
				numShow: false,
				
				list: [],
			}
		},
		onShow () {
			this.loadData()
		},
		methods: {
			loadData () {
				getBankCardInfo().then(res => {
					if (res) {
						this.list = res.data
					}
				})
			},
			addBank () {
				uni.navigateTo({
					url: '/pages/my/bank/addBank'
				})
			},
			editBank (item) {
				uni.navigateTo({
					url: '/pages/my/bank/addBank',
					success: (res) => {
						res.eventChannel.emit('onBank', {
							id: item.id,
							bank_name: item.bank_name,
							card_no: item.card_no,
							name: item.name,
							mobile: item.mobile,
						})
					}
				})
			},
			delBank (item) {
				uni.showModal({
					title: '确认要删除改卡吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({ mask: true })
							delBankCard({ id: item.id }).then(res => {
								uni.hideLoading({ noConflict: true })
								if (res) {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									})
									
									this.loadData()
								}
							})
						}
					}
				})
			},
			showActionSheet (item, index) {
				uni.showActionSheet({
					itemList: ['修改', '解除绑定'],
					success: (res) => {
						if (res.tapIndex == 0) {
							this.editBank(item)
						} else if (res.tapIndex == 1) {
							this.delBank(item)
						}
					},
					fail: (err) => {
						console.log('showActionSheet err', err);
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.bank-page {
	box-sizing: border-box;
	padding: 32rpx;
	min-height: 100%;
	background-color: $bg-color;
	.list {
		.item {
			box-sizing: border-box;
			height: 300rpx;
			margin-bottom: 20rpx;
			padding: 30rpx;
			border-radius: 8rpx;
			background-color: #dc4f51;
			position: relative;
			color: #fff;
			.name {
				font-size: 34rpx;
			}
			.look-box {
				margin-top: 20rpx;
				display: flex;
				font-size: 26rpx;
			}
			.number-box {
				margin-top: 56rpx;
				.hide {
					display: flex;
					gap: 34rpx;
					.dot-box {
						display: flex;
						gap: 8rpx;
						.dot {
							width: 12rpx;
							height: 12rpx;
							border-radius: 50%;
							background-color: #fff;
						}
					}
				}
				.number {
					font-size: 32rpx;
				}
			}
			.mord {
				position: absolute;
				top: 30rpx;
				right: 30rpx;
				width: 40rpx;
				height: 40rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				transform: rotate(90deg);
			}
		}
	}
	.add {
		height: 156rpx;
		padding: 0 32rpx;
		border-radius: 6rpx;
		background-color: #fff;
		display: flex;
		align-items: center;
		.label {
			margin-left: 24rpx;
			color: #333;
			font-size: 32rpx;
		}
	}
}
</style>
